package com.catering.controller;

import com.catering.config.Result;
import com.catering.pojo.DDishes;
import com.catering.service.DDishesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/dishes")
public class DishesController {
    @Autowired
    private DDishesService dishesService;
    @RequestMapping("/selectByDishes")
    public List<DDishes> selectByDishes(){
        return dishesService.selectByDishes();
    }
    @GetMapping("/search")
    public Result searchDishes(
            @RequestParam(required = false) String name,
            @RequestParam(required = false) BigDecimal minPrice,
            @RequestParam(required = false) BigDecimal maxPrice
    ) {
        try {
            List<DDishes> dishes = dishesService.searchDishes(name, minPrice, maxPrice);
            return Result.success(dishes);
        } catch (Exception e) {
            return Result.error("搜索失败：" + e.getMessage());
        }
    }
    @GetMapping("/selectByDish_Categories")
    public List<DDishes> selectByDish_Categories(){
        return dishesService.selectByDish_Categories();
    }
}
